<?php

Yii::import('model.Module');
Yii::import('model.Menu');
Yii::import('model.UserInfo');
class SidaBar extends CWidget
{
	public $currentUrl = '';
	public $current_module_id =1;
	public function run() {
		
		//当前位置
		if ($this->currentUrl)
		{		
			$currentMenu = Menu::getInstance()->getMenuByUrl($this->currentUrl);
			if ($currentMenu){
				$data['current_module_id'] = $currentMenu['module_id'];
				$data['current_module'] =  Module::getInstance()->getModuleInfo($currentMenu['module_id']);
			}		
		}else {
			exit("current_url_error");
		}
		$user_info = UserInfo::getInstance()->getUserInfo($_SESSION['uid']);
		$user_info['shortcuts'] = $user_info['shortcuts'] ? explode(',', $user_info['shortcuts']) : array();
		
		$appid  = $_SESSION['app_id'];

		$menu = Menu::getInstance()->getMenuByUserPermission($user_info['group_role'],$appid);
		$module = array();
		foreach ($menu as $val)
		{
			$module[$val['module_id']]['menu_list'][] = $val;
			$module[$val['module_id']]['module_name'] = $val['module_name'];
			$module[$val['module_id']]['module_id'] = $val['module_id'];
			$module[$val['module_id']]['module_icon'] = $val['module_icon'];
		}
		$data['module'] = $module;
		$data['currentMenu'] = $currentMenu;
		$data['user_info'] = $user_info;
       	$this->render('sidebar',$data);        
    }
}

